+2006-12-28 Carlos Garnacho <carlosg@gnome.org>
+
+ Make GtkNotebook able to drop detached tabs anywhere. Bug #360225.
+
+ * gtk/gtkwidget.c (gtk_widget_class_init): add "drag-failed" signal.
+ * gtk/gtkmarshalers.list: add new marshaler definition.
+ * gtk/gtkenums.h: add GtkDragResult enum.
+
+ * gtk/gtkdnd.c (gtk_drag_drop_finished): emit "drag-failed" if DND
+ operation wasn't successful.
+ (_gtk_drag_source_handle_event) (gtk_drag_drop)
+ (gtk_drag_selection_get) (gtk_drag_cancel) (gtk_drag_key_cb)
+ (gtk_drag_grab_broken_event_cb) (gtk_drag_grab_notify_cb)
+ (gtk_drag_button_release_cb) (gtk_drag_abort_timeout): tell
+ gtk_drag_drop_finished() the operation result.
+
+ * gtk/gtknotebook.c (gtk_notebook_drag_failed): new function.
+ (gtk_notebook_drag_data_get): do not call window creation hook here.
+ (gtk_notebook_init): do not set "application/x-rootwindow-drop"
+ target, instead connect to "drag-failed".
+ (gtk_notebook_draw_focus): fix potential crasher if cur_page is NULL.
+
2006-12-28 Mikael Hallendal <micke@imendio.com>
* gdk/quartz/gdkevents-quartz.c: Factored out the event loop
static void gtk_drag_drop (GtkDragSourceInfo *info,
guint32 time);
static void gtk_drag_drop_finished (GtkDragSourceInfo *info,
- gboolean success,
+ GtkDragResult result,
guint time);
static void gtk_drag_cancel (GtkDragSourceInfo *info,
+ GtkDragResult result,
guint32 time);
static gboolean gtk_drag_source_event_cb (GtkWidget *widget,
gtk_widget_pop_colormap ();
gtk_widget_set_events (window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
- gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
+ gtk_widget_set_app_paintable (window, TRUE);
if (stock_id)
{
break;
case GDK_DROP_FINISHED:
- gtk_drag_drop_finished (info, TRUE, event->dnd.time);
+ gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, event->dnd.time);
break;
default:
g_assert_not_reached ();
static void
gtk_drag_drop_finished (GtkDragSourceInfo *info,
- gboolean success,
+ GtkDragResult result,
guint time)
{
+ gboolean success;
+
+ success = (result == GTK_DRAG_RESULT_SUCCESS);
gtk_drag_source_release_selections (info, time);
if (info->proxy_dest)
}
else
{
+ if (!success)
+ g_signal_emit_by_name (info->widget, "drag_failed",
+ info->context, result, &success);
+
if (success)
{
gtk_drag_source_info_destroy (info);
time);
/* FIXME: Should we check for length >= 0 here? */
- gtk_drag_drop_finished (info, TRUE, time);
+ gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, time);
return;
}
tmp_list = tmp_list->next;
}
- gtk_drag_drop_finished (info, FALSE, time);
+ gtk_drag_drop_finished (info, GTK_DRAG_RESULT_NO_TARGET, time);
}
else
{
gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
break;
case TARGET_MOTIF_SUCCESS:
- gtk_drag_drop_finished (info, TRUE, time);
+ gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, time);
gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
break;
case TARGET_MOTIF_FAILURE:
- gtk_drag_drop_finished (info, FALSE, time);
+ gtk_drag_drop_finished (info, GTK_DRAG_RESULT_NO_TARGET, time);
gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
break;
default:
*************************************************************/
static void
-gtk_drag_cancel (GtkDragSourceInfo *info, guint32 time)
+gtk_drag_cancel (GtkDragSourceInfo *info, GtkDragResult result, guint32 time)
{
gtk_drag_end (info, time);
gdk_drag_abort (info->context, time);
- gtk_drag_drop_finished (info, FALSE, time);
+ gtk_drag_drop_finished (info, result, time);
}
/*************************************************************
switch (event->keyval)
{
case GDK_Escape:
- gtk_drag_cancel (info, event->time);
+ gtk_drag_cancel (info, GTK_DRAG_RESULT_USER_CANCELLED, event->time);
return TRUE;
case GDK_space:
|| event->grab_window == info->ipc_widget->window)
return FALSE;
- gtk_drag_cancel (info, gtk_get_current_event_time ());
+ gtk_drag_cancel (info, GTK_DRAG_RESULT_GRAB_BROKEN, gtk_get_current_event_time ());
return TRUE;
}
/* We have to block callbacks to avoid recursion here, because
gtk_drag_cancel calls gtk_grab_remove (via gtk_drag_end) */
g_signal_handlers_block_by_func (widget, gtk_drag_grab_notify_cb, data);
- gtk_drag_cancel (info, gtk_get_current_event_time ());
+ gtk_drag_cancel (info, GTK_DRAG_RESULT_GRAB_BROKEN, gtk_get_current_event_time ());
g_signal_handlers_unblock_by_func (widget, gtk_drag_grab_notify_cb, data);
}
}
}
else
{
- gtk_drag_cancel (info, event->time);
+ gtk_drag_cancel (info, GTK_DRAG_RESULT_NO_TARGET, event->time);
}
return TRUE;
time = info->proxy_dest->proxy_drop_time;
info->drop_timeout = 0;
- gtk_drag_drop_finished (info, FALSE, time);
+ gtk_drag_drop_finished (info, GTK_DRAG_RESULT_TIMEOUT_EXPIRED, time);
return FALSE;
}
GTK_TREE_VIEW_GRID_LINES_BOTH
} GtkTreeViewGridLines;
+typedef enum {
+ GTK_DRAG_RESULT_SUCCESS,
+ GTK_DRAG_RESULT_NO_TARGET,
+ GTK_DRAG_RESULT_USER_CANCELLED,
+ GTK_DRAG_RESULT_TIMEOUT_EXPIRED,
+ GTK_DRAG_RESULT_GRAB_BROKEN,
+ GTK_DRAG_RESULT_ERROR
+} GtkDragResult;
+
G_END_DECLS
#endif /* __GTK_ENUMS_H__ */
BOOLEAN:OBJECT,BOXED,BOXED
BOOLEAN:OBJECT,OBJECT,OBJECT
BOOLEAN:OBJECT,STRING,STRING
+BOOLEAN:OBJECT,ENUM
BOOLEAN:INT
BOOLEAN:INT,INT
BOOLEAN:INT,INT,INT
guint has_scrolled : 1;
};
-static const GtkTargetEntry notebook_source_targets [] = {
+static const GtkTargetEntry notebook_targets [] = {
{ "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 },
- { "application/x-rootwindow-drop", 0, 1 }
-};
-
-static const GtkTargetEntry notebook_dest_targets[] = {
- { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 }
};
#ifdef G_DISABLE_CHECKS
GdkDragContext *context);
static void gtk_notebook_drag_end (GtkWidget *widget,
GdkDragContext *context);
+static gboolean gtk_notebook_drag_failed (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkDragResult result,
+ gpointer data);
static gboolean gtk_notebook_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
GtkDirectionType direction);
static void stop_scrolling (GtkNotebook *notebook);
+static void do_detach_tab (GtkNotebook *from,
+ GtkNotebook *to,
+ GtkWidget *child,
+ gint x,
+ gint y);
static GtkNotebookWindowCreationFunc window_creation_hook = NULL;
priv->pressed_button = -1;
priv->dnd_timer = 0;
priv->switch_tab_timer = 0;
- priv->source_targets = gtk_target_list_new (notebook_source_targets,
- G_N_ELEMENTS (notebook_source_targets));
+ priv->source_targets = gtk_target_list_new (notebook_targets,
+ G_N_ELEMENTS (notebook_targets));
priv->operation = DRAG_OPERATION_NONE;
priv->detached_tab = NULL;
priv->during_detach = FALSE;
gtk_drag_dest_set (GTK_WIDGET (notebook),
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
- notebook_dest_targets, G_N_ELEMENTS (notebook_dest_targets),
+ notebook_targets, G_N_ELEMENTS (notebook_targets),
GDK_ACTION_MOVE);
+ g_signal_connect (G_OBJECT (notebook), "drag-failed",
+ G_CALLBACK (gtk_notebook_drag_failed), NULL);
+
gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
}
* gtk_notebook_style_set
* gtk_notebook_drag_begin
* gtk_notebook_drag_end
+ * gtk_notebook_drag_failed
* gtk_notebook_drag_motion
* gtk_notebook_drag_drop
* gtk_notebook_drag_data_get
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
if (GTK_WIDGET_HAS_FOCUS (widget) && GTK_WIDGET_DRAWABLE (widget) &&
- notebook->cur_page->tab_label->window == event->window &&
- notebook->show_tabs && notebook->cur_page)
+ notebook->show_tabs && notebook->cur_page &&
+ notebook->cur_page->tab_label->window == event->window)
{
GtkNotebookPage *page;
GdkRectangle area;
priv->operation = DRAG_OPERATION_NONE;
}
+static gboolean
+gtk_notebook_drag_failed (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkDragResult result,
+ gpointer data)
+{
+ if (result == GTK_DRAG_RESULT_NO_TARGET)
+ {
+ GtkNotebookPrivate *priv;
+ GtkNotebook *notebook, *dest_notebook;
+ GdkDisplay *display;
+ gint x, y;
+
+ notebook = GTK_NOTEBOOK (widget);
+ priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
+
+ display = gtk_widget_get_display (widget);
+ gdk_display_get_pointer (display, NULL, &x, &y, NULL);
+
+ dest_notebook = (* window_creation_hook) (notebook,
+ priv->detached_tab->child,
+ x, y,
+ window_creation_hook_data);
+ if (dest_notebook)
+ do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static gboolean
gtk_notebook_switch_tab_timeout (gpointer data)
{
guint info,
guint time)
{
- GtkNotebook *dest_notebook, *notebook;
GtkNotebookPrivate *priv;
- if (data->target != gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB") &&
- (data->target != gdk_atom_intern_static_string ("application/x-rootwindow-drop") ||
- !window_creation_hook))
- return;
-
- notebook = GTK_NOTEBOOK (widget);
- priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
-
if (data->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
{
+ priv = GTK_NOTEBOOK_GET_PRIVATE (widget);
+
gtk_selection_data_set (data,
data->target,
8,
(void*) &priv->detached_tab->child,
sizeof (gpointer));
}
- else
- {
- GdkDisplay *display;
- gint x, y;
-
- display = gtk_widget_get_display (widget);
- gdk_display_get_pointer (display, NULL, &x, &y, NULL);
-
- dest_notebook = (* window_creation_hook) (notebook,
- priv->detached_tab->child,
- x, y,
- window_creation_hook_data);
- if (dest_notebook)
- do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
- }
}
static void
GRAB_BROKEN,
COMPOSITED_CHANGED,
KEYNAV_FAILED,
+ DRAG_FAILED,
LAST_SIGNAL
};
G_TYPE_NONE, 1,
GDK_TYPE_DRAG_CONTEXT);
+ /**
+ * GtkWidget::drag-failed:
+ * @widget: the object which received the signal.
+ * @drag_context: the drag context.
+ * @result: the result of the drag operation.
+ *
+ * The ::drag-failed signal is emitted on the drag source when a drag has
+ * failed. The signal handler may hook custom code to handle a failed DND
+ * operation based on the type of error, it returns %TRUE is the failure has
+ * been already handled (not showing the default "drag operation failed"
+ * animation), otherwise it returns %FALSE.
+ *
+ * Return value: %TRUE if the failed drag operation has been already handled.
+ *
+ * Since: 2.12
+ */
+ widget_signals[DRAG_FAILED] =
+ g_signal_new (I_("drag_failed"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0, _gtk_boolean_handled_accumulator, NULL,
+ _gtk_marshal_BOOLEAN__OBJECT_ENUM,
+ G_TYPE_BOOLEAN, 2,
+ GDK_TYPE_DRAG_CONTEXT,
+ GTK_TYPE_DRAG_RESULT);
+
/**
* GtkWidget::drag-motion:
* @widget: the object which received the signal.